<!-- 业务订单 -->
<template>
  <a-card :bordered="false" class="br-10">
    <div class="table-page-search">
      <a-form>
        <a-form-item label="关键词搜索">
          <a-input placeholder="请输入" v-model="queryParam.keyWord" allowClear />
        </a-form-item>
        <!-- <a-form-item label="支付状态">
          <a-select placeholder="请选择" v-model="queryParam.payStatus" allowClear>
            <a-select-option v-for="dict in Dictionary.getLocal('orderPayStatus')" :key="dict.dictValue"
              :value="dict.dictValue">
              {{ dict.dictLabel }}
            </a-select-option>
          </a-select>
        </a-form-item> -->
        <a-form-item label="订单状态">
          <a-select placeholder="请选择" v-model="queryParam.suborderStatus" allowClear>
            <a-select-option v-for="dict in Dictionary.getLocal('orderStatus')" :key="dict.dictValue"
              :value="dict.dictValue">
              {{ dict.dictLabel }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="下单时间">
          <a-range-picker format="YYYY-MM-DD" valueFormat="YYYY-MM-DD" v-model="payTime" allowClear class="width-25" />
        </a-form-item>
        <span class="search-submitButtons">
          <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
          <a-button @click="handleReset">重置</a-button>
        </span>
      </a-form>
    </div>
    <div class="table-operator disFlxJS">
      <div></div>
      <CustomTable :name="$route.name" :columns="columns" :newColumns="newColumns" />
    </div>
    <s-table size="default" ref="table" rowKey="dictId" :columns="newColumns" :data="loadData">
      <span slot="totalAmount" slot-scope="text">
        {{ !isNaN(text) ? formatMoney({
          money: text,
          isShowFree: false
        }) : text }}
      </span>

      <span slot="payAmount" slot-scope="text">
        {{ !isNaN(text) ? formatMoney({
          money: text,
          isShowFree: false
        }) : text }}
      </span>

      <span slot="merchantFee" slot-scope="text">
        {{ !isNaN(text) ? formatMoney({
          money: text,
          isShowFree: false
        }) : text }}
      </span>

      <span slot="unSplitAmount" slot-scope="text">
        {{ !isNaN(text) ? formatMoney({
          money: text,
          isShowFree: false
        }) : text }}
      </span>

      <span slot="payStatus" slot-scope="text">
        {{ text | getOrderPayStatusText }}
      </span>


      <span slot="suborderStatus" slot-scope="text">
        {{ text | getOrderTypeText }}
      </span>


      <span slot="action" slot-scope="text, record">
        <a-button v-has="'order:businessOrderDetail'" size="small" class="_mr-5" @click="handleDetail(record)">
          详情
        </a-button>
      </span>
    </s-table>
  </a-card>
</template>
  
<script>
import { STable } from '@/components'
import { getResourcesOrderList } from '@/api/order/order'
import CustomTable from '@/components/Cuscolumn'
import { formatMoney } from "@/utils/number";
import Dictionary from "@/utils/dict/Dictionary";

export default {
  components: {
    STable,
    CustomTable,
  },
  data() {
    return {
      Dictionary,
      // 查询参数
      queryParam: {
        payStatus: undefined,
        suborderStatus: undefined,
        keyWord: undefined,
        startTime: undefined,
        endTime: undefined,
      },
      // 表头
      columns: [
        {
          title: '子订单号',
          dataIndex: 'suborderNo',
        },
        {
          title: '订单来源',
          dataIndex: 'shopName',
        },
        {
          title: '应付',
          dataIndex: 'totalAmount',
          width: 80,
          scopedSlots: { customRender: 'totalAmount' },

        },
        {
          title: '实付',
          dataIndex: 'payAmount',
          width: 80,
          scopedSlots: { customRender: 'payAmount' },
        },
        {
          title: '费率',
          dataIndex: 'merchantFee',
          width: 80,
          scopedSlots: { customRender: 'merchantFee' },
        },
        {
          title: '分账金额',
          dataIndex: 'unSplitAmount',
          width: 100,
          scopedSlots: { customRender: 'unSplitAmount' },
        },
        {
          title: '支付状态',
          dataIndex: 'payStatus',
          width: 100,
          scopedSlots: { customRender: 'payStatus' },
        },
        {
          title: '订单状态',
          dataIndex: 'suborderStatus',
          width: 200,
          scopedSlots: { customRender: 'suborderStatus' },
        },
        {
          title: '下单时间',
          dataIndex: 'createTime',
          width: 214,
        },
        {
          title: '操作',
          width: '50px',
          fixed: 'right',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      orderMenuVal: 'connections',
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        var params = {
          current: parameter.pageNum,
          size: parameter.pageSize,
        }
        return getResourcesOrderList(Object.assign(params, this.queryParam))
      },
    }
  },
  filters: {
    getOrderPayStatusText(text) {
      return Dictionary.getLocal('orderPayStatus').find((v) => v.dictValue === text).dictLabel
    },
    getOrderTypeText(text) {
      return Dictionary.getLocal('orderStatus').find((v) => v.dictValue === text).dictLabel
    },
  },
  computed: {
    payTime: {
      get() {
        return [this.queryParam.startTime, this.queryParam.endTime]
      },
      set(val) {
        this.queryParam.startTime = val[0]
        this.queryParam.endTime = val[1]
      },
    },
    newColumns() {
      const currentColumns = this.$store.state.user.customTable
      if (currentColumns && currentColumns[this.$route.name]) {
        return this.$options
          .data()
          .columns.filter((v) => {
            const _items = currentColumns[this.$route.name].find((item) => item === v.title || item.title === v.title)
            if (_items) return Object.assign(v, _items)
          })
          .sort((a, b) => {
            return a.tableSort - b.tableSort
          })
      } else {
        return this.columns
      }
    },
  },
  created() { },
  methods: {
    formatMoney,
    handleReset() {
      Object.keys(this.queryParam).forEach((k) => {
        this.queryParam[k] = undefined
      })
      this.$refs.table.refresh(true)
    },
    handleDetail(row) {
      this.$router.push({
        path: '/order/resourcesOrderDetail',
        query: {
          id: row.id,
        },
      })
    },
  },
}
</script>
  